package com.cnzha.mr.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: zhaoxin
 * @email: zdkk@foxmail.com
 * @Date: 3/31/2020 3:48 PM
 */
public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //13509468723		7335	110349	117684
        String[] split = value.toString().split("\t");

        String phoneNbr = split[0];
        long upFlow = Long.parseLong(split[1]);
        long downFlow = Long.parseLong(split[2]);
        k.set(phoneNbr);
        v.set(Long.valueOf(upFlow), Long.valueOf(downFlow));
        context.write(v, k);
    }
}
